/**
* Created by Jimmy on 2017/7/16.
*/
<template>
  <div class="extra-item-content">
    <el-button type="danger" icon="el-icon-close" size="mini" circle @click="deleteSelf"></el-button>

    <!--<button type="button" class="btn btn-warning btn-xs operate" v-on:click="deleteSelf">-->
      <!--<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>-->
    <!--</button>-->
    <div class="column-warp">
      <select v-model="extra_item.project_selected">
        <option :value = "i" v-for="(sub, i) in extra_item.projects">
          {{  sub.name }}
        </option>
      </select>
    </div>
    <div class="column-warp project-desc">
      <input type="text" placeholder="项目描述" v-model.number="extra_item.projects[extra_item.project_selected].project_desc"/>
    </div>
    <div class="column-warp">
      <span>{{ extra_item.projects[extra_item.project_selected].unit }}</span>
    </div>
    <div class="column-warp">
      <span>{{ extra_item.projects[extra_item.project_selected].prices }}</span>
    </div>
    <div class="column-warp">
      <input type="text" placeholder="系(根)数" v-model.number="extra_item.projects[extra_item.project_selected].coefficient"/>
    </div>
    <div class="column-warp">
      <input type="text" placeholder="数量" v-model.number="extra_item.projects[extra_item.project_selected].quantity"/>
    </div>
    <div class="column-warp">
      <span>{{ extra_item.projects[extra_item.project_selected].total }}</span>
    </div>
    <div class="column-warp">
      <input type="text" placeholder="说明" v-model.number="extra_item.projects[extra_item.project_selected].description"/>
    </div>
    <div class="column-warp">
      <span>{{ extra_item.projects[extra_item.project_selected].reference }}</span>
    </div>
  </div>
</template>

<script>
  export default {
    props: {
      index: Number,
      extra_item: Object
    },
    watch: {
      extra_item: {
        handler: function (newitem) {
          this.extra_item.projects[this.extra_item.project_selected].total = this.calculateTotal(newitem)
        },
        deep: true
      }
    },
    methods: {
      calculateTotal: function (newitem) {
        var coefficient = newitem.projects[newitem.project_selected].coefficient
        var price = newitem.projects[newitem.project_selected].prices
        var quantity = newitem.projects[newitem.project_selected].quantity
        return (coefficient * price * quantity).toFixed(2)
      },
      deleteSelf: function () {
        this.$emit('deleteExtraItem', this.index)
      }
    }
  }
</script>

<style scoped>
  .extra-item-content{
    height: 30px;
    /*background: red;*/
    text-align: left;
    margin: 10px 0;
    display: flex;
    flex-flow: row;
    line-height: 30px;
  }
  .el-button.is-circle{
    /*width: 28px;*/
    height: 28px;
    /*margin-top: 6px;*/
  }
  .operate{
    /*flex: 0 0 20px;*/
    color: white;
    height: 20px;
    margin: 5px 10px 5px 0;
  }
  .column-warp{
    flex-grow: 1;
    flex-basis: 0;
    flex-shrink: 0;
    margin: 0 5px;
    height: 30px;
    text-align: center;
  }
  .column-warp:last-of-type{
    margin-right: 0;
  }
  .column-warp select{
    outline: none;
    height: 30px;
    width: 100%;
    overflow: hidden;
  }
  .extra-item-content input{
    outline: none;
    width: 100px;
    line-height: 25px;
    padding:  0 10px;
    border: 1px solid #ededed;
  }
  .extra-item-content input:focus{
    border: 1px solid #e74c3c;
  }
  .extra-item-content .project-desc{
    flex-grow: 3;
    flex-basis: 0;
    padding: 0 10px;
  }
  .extra-item-content .project-desc input{
    width: 200px;
  }

</style>
